<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of gangmemberchange
 *
 * @author Dragon.hu add @2015.9.10
 */
defined('BASEPATH') or die('forbidden');

class Gangmemberchange_Controller extends Controller {

	private $inc;
	private $logdb;	//数据库连接
	private $platformList;	//平台列表
	private $gangjoblist;  //公会职务
	private $actionlist; 
	private $approve;
	
	function _init() {
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		
		$this->inc = $this->config['inc'];
		$this->platformList = $this->inc['platform_list'];
		$this->gangjoblist = array('-1' => '无', '0' => '会长', '1' => '副会长', '2' => '精英', '3' => '会员' );
		$this->actionlist = array('1' => '加入', '2' => '退出', '3' => '申请', '4' => '晋升', '5' => '降级');
		$this->approve = array('1' => '是', '2' => '否');
		
        // log数据库
		//$this->logdb = $this->load->database('log_db');
		//得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
		if ($areanum == '')
		{
			echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
			return;
		}
		// log数据库
		$this->logdb = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
		
		if (false == $this->logdb) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
	}

	function index() {
		$this->view->display("log_gang/gangmemberchange/index");
	}

	function flexigrid() {
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();

		$sql = "SELECT COUNT(*) AS num FROM gang_member_change where {$where} ";
		
		$one = $this->logdb->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
			
		$sql = "SELECT {$colsinfo} FROM gang_member_change where {$where}  {$orderby} LIMIT {$offset},{$rp}";
		
		$this->logdb->query($sql);
		
		while ($n = $this->logdb->get_array('default'))
		{
			$n['platform_id']=$this->platformList[$n['platform_id']]."(".$n['platform_id'].")";
			$n['job']=$this->gangjoblist[$n['job']]."(".$n['job'].")";
			$n['action']=$this->actionlist[$n['action']]."(".$n['action'].")";
			$n['approve']=$this->approve[$n['approve']]."(".$n['approve'].")";
			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		
		echo json_encode($result);
	}

}
